package com.bbm.communitysystem.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bbm.communitysystem.domain.UserCred;
import com.bbm.communitysystem.domain.bo.UserCredBo;
import com.bbm.communitysystem.domain.dto.UserCredDto;
import com.bbm.communitysystem.mapper.UserCredMapper;
import com.bbm.communitysystem.service.IUserCredService;
import com.bbm.communitysystem.tools.SHA256;
import org.springframework.stereotype.Service;

@Service
public class UserCredImpl extends ServiceImpl<UserCredMapper, UserCred> implements IUserCredService {

    @Override
    public UserCredDto registerUserCredDto(UserCredBo userCredBo) {

        UserCred userCred = BeanUtil.copyProperties(userCredBo, UserCred.class);

        userCred.setStatus(1);
        userCred.setUpdateBy("0");
        userCred.setUpdateTime(System.currentTimeMillis() + "");
        userCred.setPassword(SHA256.encryption(userCredBo.getPassword()));

        boolean save = save(userCred);

        if (!save) {
            return null;
        }

        return BeanUtil.copyProperties(userCred, UserCredDto.class);
    }
}
